'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);
  router.post('/api/upload/file2', controller.upload2.index);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);
  // news
  router.get('/api/news/list', controller.news.allList);
  router.resources('news', '/api/news', controller.news);
  // 会员
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
    // 诊断记录
    router.get('/api/diagnosis/list', controller.diagnosis.allList);
    router.resources('diagnosis', '/api/diagnosis', controller.diagnosis);
    // 用户咨询
    router.get('/api/consult/list', controller.consult.allList);
    router.resources('consult', '/api/consult', controller.consult);
    // 评论
    router.get('/api/comment/list', controller.comment.allList);
    router.resources('comment', '/api/comment', controller.comment);
    // 颜色
    router.get('/api/color/list', controller.color.allList);
    router.resources('color', '/api/color', controller.color);
};
